<?php
include_once '../header1.php';
?>
<link rel="stylesheet" type="text/css" media="all" href="../js/jsTeacher_NICPick_ltr.min.css" />
<script type="text/javascript" src="../js/jsTeacher_NICPick.min.1.3.js"></script>
<script type="text/javascript">
	window.onload = function(){
		new JsTeacher_NICPick({
			useMode:2,
			target:"inputField",
			Teacher_NICFormat:"%Y-%m-%d"
			
		});
	};
</script>
</head>
<body>
<?php
include_once ("../Login/databaseconnection.php");

if(!loggedin())
{
	require_once ("../index.php");
}
   
   else
   {
	if(isset($_POST['Register']))
{
$Training_Id=$_POST['Training_Id'];
$Started_year=$_POST['Started_year'];
$Institute=$_POST['Institute'];
$Teacher_NIC=$_POST['Teacher_NIC'];
$New_Training=$_POST['New_Training'];
$Tr_Che=mysql_query("SELECT * FROM training_details WHERE Training_Id='$Training_Id' AND Teacher_NIC='$Teacher_NIC'");
if($rows=mysql_fetch_array($Tr_Che))
		{
			$_SESSION['errorexi']="Sorry this Training details for this teacher is already exists";
		}
		else
		{
		if($_SESSION['Access_Type']=="Teacher in Charge")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
  $get_teaSch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$Teacher_NIC'");
  if($rowsesch=mysql_fetch_array($get_teaSch))
{
$schid=$rowsesch['School_Id'];
if($schid==$Own_School_Id)
{
require_once 'inserttraining.php';
	}
		 else
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
		}
		}
}
		else if($_SESSION['Access_Type']=="Administrator")
{
require_once 'inserttraining.php';
}   
   else
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
	}
}  
?>
<?php
include_once "../header2.php";
?><?php
include_once "topmenu.php";
?>

<div id="content">
	<div id="main">
	  <div id="bodyfield">
      <div id="lefttablereg">
  <form name="form1" action="#" method="POST">
  <table width="800" height="172" border="0" class="tablefontv">
    <tr>
      <td height="23" colspan="7"  scope="row" class="err"><?php
		if(isset($_POST['Register']))
{
	if(isset($_SESSION['errornotallo']))
{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['errornotallo'];
unset($_SESSION['errornotallo']);
}
	if(isset($_SESSION['errorin']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errorin'];
		unset($_SESSION['errorin']);
	}
	if(isset($_SESSION['error']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['error'];
		unset($_SESSION['error']);
		
	}
		if(isset($_SESSION['errorexi']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errorexi'];
		unset($_SESSION['errorexi']);
		
	}
}
		?></td>
      </tr>
    <tr>
      <th width="22" rowspan="10"  scope="row">&nbsp;</th>
      <td width="37"  scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
      <td width="210" height="24"  scope="row">Teacher NIC:</td>
       <td>
	   <select name="Teacher_NIC" value="select">
      <?php
	  
	  if(isset($_POST['Register']))
	  {
	  $tra_tea=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='".$Teacher_NIC."'");
	 if($row_tea=mysql_fetch_array($tra_tea))
	 {
	 $Teacher_Name=$row_tea['First_Name']." ".$row_tea['Last_Name']."(".$Teacher_NIC.")";
	 }
	 echo '<option value="'.$Teacher_NIC.'">'.$Teacher_Name.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  $scho=mysql_query("SELECT DISTINCT(T_NIC_Number) FROM teacher");
	 while($row=mysql_fetch_array($scho))
  {
	  $T_NIC=$row['T_NIC_Number'];
	  $tra_tea=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='".$T_NIC."'");
	 if($row_tea=mysql_fetch_array($tra_tea))
	 {
	 $Teacher_Name=$row_tea['First_Name']." ".$row_tea['Last_Name']."(".$T_NIC.")";
	 }
if($Teacher_NIC!=$T_NIC)
{
	  echo '<option value="'.$T_NIC.'">'.$Teacher_Name.'</option>';
}
  }
	  ?>
    </select> 
	  </td>
      </tr>
      <tr>
        <td scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
	  <td height="24" scope="row">Training Name:</td>
	   <td><select name="Training_Id" id="Training_Id">
        <?php	  
	  if(isset($_POST['Register']))
	  {
	  $tra_pro=mysql_query("SELECT * FROM training WHERE Training_Id='".$Training_Id."'");
	 if($row_tra=mysql_fetch_array($tra_pro))
	 {
	 $Training_name=$row_tra['Training_Name'];
	 }
	 echo '<option value="'.$Training_Id.'">'.$Training_name.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  $com=mysql_query("SELECT DISTINCT(Training_Id) FROM training");
	  
  while($row=mysql_fetch_array($com))
  {
	 $Tra_Id=$row['Training_Id'];
	 $tra_pro=mysql_query("SELECT * FROM training WHERE Training_Id='".$Tra_Id."'");
	 if($row_tra=mysql_fetch_array($tra_pro))
	 {
	 $Tra_name=$row_tra['Training_Name'];
	 }
if($Tra_Id!=$Training_Id)
{
	  echo '<option value="'.$Tra_Id.'">'.$Tra_name.'</option>';
}
  }
 
	  ?>
      </select><br/><label><font color="red">or</font> New training programme:</label>&nbsp;&nbsp;&nbsp;
	  <?php
	  if($New_Training!="")
	  {
	  echo "<input type='text' name='New_Training' value='$New_Training'/>";
	  }
	  else
	  {
	  echo "<input type='text' name='New_Training'/>";
	  }
	  ?></td>
     </tr>
	 <tr>
      <td scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
      <td height="22" scope="row">Institute: </td>    
	    <?php
	   if(isset($_POST['Register']))
{
echo '<td>';
echo "<input type='text' name='Institute' value='$Institute'/>";
echo '</td>';

}
else
{
echo '<td>';
echo "<input type='text' name='Institute'/>";
echo '</td>';

}?>
       <td width="201">&nbsp;</td>
      </tr>
    <tr>
      <td scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
      <td height="22" scope="row">Duration: </td>
    
	    <?php
	   if(isset($_POST['Register']))
{
echo '<td>';
echo "<input type='text' name='Duration' value='$Duration'/>";
echo '</td>';

}
else
{
echo '<td>';
echo "<input type='text' name='Duration'/>";
echo '</td>';

}?>
       <td width="201">&nbsp;</td>
      </tr>
	  <tr>
      <td scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
      <td height="22" scope="row">Started year: </td>
    
	    <?php
	   if(isset($_POST['Register']))
{
echo '<td>';
echo "<input type='text' name='Started_year' value='$Started_year'/>";
echo '</td>';

}
else
{
echo '<td>';
echo "<input type='text' name='Started_year'/>";
echo '</td>';

}?>
       <td width="201">&nbsp;</td>
      </tr>
	  <tr>
	    <th height="31" colspan="3" scope="row"></th> 
	  </tr>
  </table>
  <br/>
  <a href="insert.php" class="reset">Reset |</a>
  <input name="Register" align="middle" type="submit" value="Register" class="buttonok"/>
 </form>
  </div>
  <div id="righttablereg">
    <?php
		if(isset($_POST['Register']))
{
if(isset($_SESSION['OK']))
{
$result=mysql_query("SELECT * FROM training_details");
echo '<br/>';
if(mysql_num_rows($result)!=0)
   {

echo '<table width="208" border="1" class="tablefontv">
<tr bgcolor="#6AB5FF">
<td><font color="#000000">Training Id</font></td>
<td><font color="#000000">Teacher NIC Number</font></td>
<td><font color="#000000">Duration</font></td>
<td><font color="#000000">Training Name</font></td>
<td><font color="#000000">Last Updated Date</font></td>
</tr>';

  while($row=mysql_fetch_array($result))
  {
    $Training_Id=$row['Training_Id'];
$res=mysql_query("SELECT * FROM  training WHERE Training_Id='$Training_Id'");
if($rowc=mysql_fetch_array($res))
{
$Training_Name=$rowc['Training_Name'];
}
  $Tra_Id=$_SESSION['Training_Id'];
  $Teacher_NIC=$_SESSION['Teacher_NIC'];
 $Duration=$_SESSION['Duration'];
  if($row['Training_Id']=="$Tra_Id"&&$row['Teacher_NIC']=="$Teacher_NIC"&&$row['Duration']=="$Duration")
  {
    echo '<tr bgcolor="#936">';
    echo '<td><font color="#000000">'.$row['Training_Id'].'</font></td>';
    echo '<td><font color="#000000">'.$row['Teacher_NIC'].'</font></td>';
    echo '<td><font color="#000000">'.$row['Duration'].'</font></td>';
	 echo '<td><font color="#000000">'.$rowc['Training_Name'].'</font></td>';
	 echo '<td><font color="#000000">'.$row['Last_Updated_Date'].'</font></td>';
  echo '</tr>';
  unset($_SESSION['Training_Id']);
  unset($_SESSION['Teacher_NIC']);
  unset($_SESSION['Duration']);
  }
 else
  {
  
    echo '<tr bgcolor="#CCCCCC">';
    echo '<td>'.$row['Training_Id'].'</td>';
    echo '<td>'.$row['Teacher_NIC'].'</td>';
    echo '<td>'.$row['Duration'].'</td>';
    echo '<td>'.$Training_Name.'</td>';
		echo '<td>'.$row['Last_Updated_Date'].'</td>';
  echo '</tr>';
  }
  }
   echo "</table>";

  }
  unset($_SESSION['OK']);
  }
  }
  
  ?>
    </div>
</div>
</div>
</div>
<div id="sidebar"><br/>
<div id="partners" class="boxed">
<h2 class="title">TRAINING DETAILS</h2>
</div>
<?php
include_once "menu.php";
?>
 <?php
include_once "../footer.php";
?>
<?php
}
?>
</body>
</html>